package com.xbongbong.saas.model.impl;

import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.enums.DelEnum;
import com.xbongbong.pro.domain.dao.AiAssistantDao;
import com.xbongbong.pro.domain.entity.AiAssistantEntity;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.model.AiAssistantModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description: 智能助手
 * @Author: hongxiao
 * @date: 2019-04-23 20:03
 * @since v1.0
 */
@Service("aiAssistantModel")
public class AiAssistantModelImpl implements AiAssistantModel {

    @Resource
    private AiAssistantDao aiAssistantDao;

    @Override
    public Integer insert(AiAssistantEntity entity){
        return aiAssistantDao.insert(entity);
    }

    @Override
    public Integer update(AiAssistantEntity entity){
        return aiAssistantDao.update(entity);
    }

    @Override
    public List findEntitys(Map<String, Object> param) {
        return aiAssistantDao.findEntitys(param);
    }

    @Override
    public Integer getEntitysCount(Map<String, Object> param) {
        return aiAssistantDao.getEntitysCount(param);
    }

    @Override
    public List findEntitysWithoutSub(Map<String, Object> param) {
        return null;
    }

    @Override
    public Integer save(AiAssistantEntity entity){

        if(entity.getId() == null || entity.getId().equals(0L)) {
            return aiAssistantDao.insert(entity);
        }
        return aiAssistantDao.update(entity);
    }

    @Override
    public Integer deleteByKey(Long key, String corpid) {return aiAssistantDao.deleteByKey(key, corpid);}

    @Override
    public void insertBatch(List<AiAssistantEntity> entityList) {
        aiAssistantDao.insertBatch(entityList);
    }

    @Override
    public AiAssistantEntity getByKey(Long key, String corpid) {
        return aiAssistantDao.getByKey(key, corpid);
    }

    @Override
    public List<String> findCorps(Map<String, Object> param) {
        return aiAssistantDao.findCorps(param);
    }

    @Override
    public Integer getCorpsCount() {
        return aiAssistantDao.getCorpsCount();
    }

    @Override
    public Integer getEnableCount(String corpid) {
        Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        param.put(StringConstant.CORPID, corpid);
        param.put("enable", BasicConstant.IS_USE);
        param.put("del", DelEnum.NORMAL.getDel());
        return getEntitysCount(param);
    }

    @Override
    public List<AiAssistantEntity> getListByOneCondition(String corpid, Long formId) {
        return aiAssistantDao.getOneCondition(corpid, formId);
    }

    @Override
    public Boolean hasJxcSmart(String corpid) {
        List<Integer> jxcBusinessTypeList = Arrays.asList(XbbRefTypeEnum.SUPPLIER.getCode(), XbbRefTypeEnum.PURCHASE.getCode(),
                XbbRefTypeEnum.PAY_PLAN.getCode(), XbbRefTypeEnum.PRODUCTION_ORDER.getCode(), XbbRefTypeEnum.PRODUCT.getCode());
        Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        param.put(StringConstant.CORPID, corpid);
        param.put("del", DelEnum.NORMAL.getDel());
        param.put("saasMark", SaasMarkEnum.SAAS.getCode());
        param.put("businessTypeIn", jxcBusinessTypeList);
        return getEntitysCount(param) > 0;
    }

    @Override
    public void updateBatch(List<AiAssistantEntity> entityList, String corpid) {
        aiAssistantDao.updateBatch(entityList, corpid);
    }

    @Override
    public List<String> getCorpidList() {
        return aiAssistantDao.getCorpidList();
    }
}
